package sample;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        //创建一个button
        Button button = new Button("say HelloWorld");
        //为按钮添加事件
        button.setOnAction(new MyButtonEvent());

        //创建一个面板，并将按钮添加到面板上
        StackPane root = new StackPane();
        root.getChildren().add(button);

        //创建一个场景，并将面板添加到场景上
        Scene scene = new Scene(root);

        //准备阶段
        primaryStage.setScene(scene);
        primaryStage.setTitle("First JavaFX Application");
        primaryStage.show();
    }

    /**
     * 按钮事件类
     */
    class MyButtonEvent implements EventHandler<ActionEvent> {
        @Override
        public void handle(ActionEvent event) {
            System.out.println("Hello World");
        }
    }


    public static void main(String[] args) {
        launch(args);
    }
}
